﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ALDIOrganizer
{
    public partial class ChooseTemplate : Form
    {
        internal string GetChoice
        {
            get
            {
                return rbBaseOn.Checked ?
                    lbTemplates.SelectedValue.ToString() :
                    String.Empty;
            }
        }
        public ChooseTemplate()
        {
            InitializeComponent();
        }

        public ChooseTemplate(
            string pGroupBoxTitle,
            bool pAllowNone)
            : this()
        {
            gbxMain.Text = pGroupBoxTitle;
            rbBaseOn.Checked = true;
            rbDontBaseOn.Enabled = pAllowNone;
            lbBlankTemplateExplanation.Visible = pAllowNone;
        }

        private void ChooseBaseTemplate_Load(object sender, EventArgs e)
        {
            lbTemplates.DataSource = Program.CurrentFile.TemplatesDataSource;
            lbBlankTemplateExplanation.Text =
                lbBlankTemplateExplanation.Text.Replace("#",
                Template.DefaultName);
            if (lbTemplates.Items.Count == 0)
            {
                rbBaseOn.Checked = false;
                rbBaseOn.Enabled = false;
                rbDontBaseOn.Checked = true;
            }
            else
            {
                rbBaseOn.Checked = true;
            }
        }

        private void lbTemplates_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbTemplates.SelectedIndex >= 0)
            {
                rbBaseOn.Checked = true;
            }
        }
    }
}
